strArray[1] = "World" ;
Recall these facts about all arrays:
String
".
Frequent Bug: It is easy to confuse the length of an array with the number
of cells that contain a reference.
In the example, only two cells contain references to String
s, but
strArray.length
will be 8.
Abundant Source of Hopeless Confusion: Often people say "an array of Strings" or "a String in the array" when really they should say "an array of String references" or "a String referenced by a cell of the array". This can lead to confusion. Be careful when you encounter such phrases.
Here is a section of code that declares and constructs the array, and puts
some more String
s into it:
// combined statement String[] strArray = new String[8] ; strArray[0] = "Hello" ; strArray[1] = "World" ; strArray[2] = "Greetings" ; strArray[3] = "Jupiter" ;
Must all the String
s in the array be of the same length?
Remember, this really should ask "must all of the String
s referred to by cells of the array be of the same length?".